#ifndef __ILIB_CORE_THREAD_H__
#define __ILIB_CORE_THREAD_H__

#include "../../iHeader.h"
#include "../h/iEvent.h"

#if defined(__WIN__)
typedef uintptr_t os_thread_t;
#define TLS _declspec(thread)
#elif defined(__LINUX__)
typedef pthread_t os_thread_t;
#define TLS __thread
#endif

class iThread
{
public:
	iThread();
	virtual ~iThread();

	int start();
	int stop(uint32_t ms);
	long get_id();

	uint32_t wait(unsigned int ms=50);
	virtual int run() = 0;

private:
    #if defined(__WIN__)
	static void thread_run(void* param);
    #elif defined(__LINUX__)
	static void* thread_run(void* param);
    #endif

protected:
	bool		m_runing;
	iEvent		m_event;
	os_thread_t	m_thread;
	long		m_id;

public:
    static TLS iThread* tls_thread;
};
#endif  //__ILIB_CORE_THRED_H__
